package org.bapoint.bawirelessprogressusercenter.exception;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bapoint.bawirelessprogressusercenter.entity.vo.AjaxResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;

import java.util.ResourceBundle;

/**
 * @class ExceptionHandler
 * @Author wyp
 * @Description 全局异常处理
 * @Date 2022/12/19
 * @Version 1.0
 */
@ControllerAdvice
public class ExceptionHandler {
    protected static final ResourceBundle RES = ResourceBundle.getBundle("strings/exception");
    private static final Log logger = LogFactory.getLog(ExceptionHandler.class);

    @org.springframework.web.bind.annotation.ExceptionHandler({AppException.class})
    public ResponseEntity<AjaxResult<?>> petsLoverExceptionHandler(AppException ex) {
        logger.error("petsLover exception", ex);
        AjaxResult<?> result = new AjaxResult<>();
        result.setMessage(ex.getMessage());
        result.setCode(ex.getErrorCode());

        return ResponseEntity.status(HttpStatus.OK).body(result);
    }

    public static void main(String[] args) {
        System.out.println(RES.getString("appName.en"));
        System.out.println(RES.getString("appName.ch"));
    }
}